//
//  ViewController.m
//  QingTengGaoXiao
//
//  Created by 沈煜航 on 2018/10/3.
//  Copyright © 2018年 QingTeng. All rights reserved.
//

#import "ViewController.h"
#import "detailedMajorView.h"
#import "detailedSchoolView.h"

@interface ViewController ()

@end

@implementation ViewController

#pragma viewController的生命周期方法

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initSchoolView];
}

#pragma 初始化方法

//初始化主视窗，当回到最初的三个主页面时调用
-(void)initView{
    //隐藏按钮
    self.retuenButton.enabled = NO;
    self.retuenButton.hidden = YES;
    self.starButton.enabled = NO;
    self.starButton.hidden = YES;
    //重制底部三个button及label
    self.schoolButton.enabled = YES;
    self.individualButton.enabled = YES;
    self.talkButton.enabled = YES;
    [self.schoolButtonLabel setTextColor:[UIColor blackColor]];
    [self.individualButtonLabel setTextColor:[UIColor blackColor]];
    [self.talkButtonLabel setTextColor:[UIColor blackColor]];
    //清理主要功能视窗上的子视窗
    for(UIView* view in self.mainView.subviews){
        [view removeFromSuperview];
    }
}

-(void)initSchoolView{
    self.schoolButton.enabled = NO;
    [self.schoolButtonLabel setTextColor:[UIColor grayColor]];
    schoolView* view = [[schoolView alloc] init];
    [self.mainView addSubview:view];
    [view changeTitle];
}

-(void)initIndividualView{
    self.individualButton.enabled = NO;
    [self.individualButtonLabel setTextColor:[UIColor grayColor]];
    individualView* view = [[individualView alloc] init];
    [self.mainView addSubview:view];
     [view changeTitle];
}

-(void)initTalkView{
    self.talkButton.enabled = NO;
    [self.talkButtonLabel setTextColor:[UIColor grayColor]];
    talkView* view = [[talkView alloc] init];
    [self.mainView addSubview:view];
     [view changeTitle];
}

#pragma 控制器方法



#pragma 按钮的action实现

- (IBAction)returnButtonAction:(UIButton *)sender {
    [self.mainView.subviews.lastObject removeFromSuperview];
    [self.mainView.subviews.lastObject changeTitle];
    if(self.mainView.subviews.count == 1){
        //返回按钮消失
        self.retuenButton.enabled = NO;
        self.retuenButton.hidden = YES;
    }
    self.starButton.enabled = NO;
    self.starButton.hidden = YES;
}

- (IBAction)starButtonAction:(UIButton *)sender {
    NSString* className = NSStringFromClass(self.mainView.subviews.lastObject.class);
    if(sender.selected == NO){
        //没有被选中过，则进行收藏操作
        if([className isEqualToString:@"detailedSchoolView"]){
            detailedSchoolView* school = self.mainView.subviews.lastObject;
            NSInteger num = school.schoolNumber;
            //保存到收藏的学校的plist里
            
        }
        if([className isEqualToString:@"detailedMajorView"]){
            detailedMajorView* major = self.mainView.subviews.lastObject;
            NSInteger num = major.majorNumber;
            //保存到收藏的专业的plist里
            
        }
    }
    else{
        //被选中过，则进行移除收藏操作
        if([className isEqualToString:@"detailedSchoolView"]){
            detailedSchoolView* school = self.mainView.subviews.lastObject;
            NSInteger num = school.schoolNumber;
            //从收藏的学校的plist里移除
            
        }
        if([className isEqualToString:@"detailedMajorView"]){
            detailedMajorView* major = self.mainView.subviews.lastObject;
            NSInteger num = major.majorNumber;
            //从收藏的专业的plist里移除
            
        }
    }
    
}

- (IBAction)actionOfButtonsInBottom:(UIButton *)sender {
    [self initView];
    switch (sender.tag) {
        case 1:
            [self initSchoolView];
            break;
        case 2:
            [self initIndividualView];
            break;
        case 3:
            [self initTalkView];
            break;
        default:
            break;
    }
}
@end
